﻿using System;
using System.Collections.Generic;
using System.IO;
using CSJ2K.Util.IO;

namespace CSJ2K.Jpc.Segments
{
    /// <summary>Comment (COM)</summary>
    /// <comment>
    /// Function: Allows unstructured data in the main and tile-part header.  
    /// Usage: Main and tile-part headers. Repeatable as many times as desired in either or 
    ///      both the main or tile-part headers. This marker segment has no effect on 
    ///      decoding the codestream. 
    /// Length: Variable depending on the length of the message.
    /// </comment>
    public class COM : Segment
    {
        /// <summary>Registration value of the marker segment.</summary>
        public ushort R;

        /// <summary>Byte of unstructured data.</summary>
        public byte[] C;

        public COM(Stream source)
            : this(source, (Markers)StreamUtil.ReadBUInt16(source)) { }
        public COM(Stream source, Markers marker)
            : base(source, marker, true)
        {
            if (marker != Markers.COM) throw (new ApplicationException("Attempting to create segment of the wrong type."));

            R = StreamUtil.ReadBUInt16(source);
            C = StreamUtil.ReadBytes(source, Length - 4);
        }
    }
}
